#!/bin/bash
###SHELLPACK preamble frontistr v5.0
WEB_LOCATION="https://gitlab.com/FrontISTR-Commons/FrontISTR/-/archive"
MIRROR_LOCATION="$WEBROOT/frontistr/"

###SHELLPACK mpi_setup_deps FRONTISTR_OPENMPI_VERSION
###SHELLPACK mpi_setup_env FRONTISTR_OPENMPI_VERSION FRONTISTR_MPI_PATH FRONTISTR_MPI_LIBPATH

###SHELLPACK parseargBegin
###SHELLPACK parseargEnd

###SHELLPACK sources_fetch ${VERSION}/FrontISTR-${VERSION}.tar.gz frontistr-${VERSION}
###SHELLPACK build_start frontistr-${VERSION}

###SHELLPACK self_extract FrontISTR-v5.0-Makefile.conf.org.diff
cp Makefile.conf.org Makefile.conf
cat $SHELLPACK_TEMP/FrontISTR-v5.0-Makefile.conf.org.diff | patch -p1 || \
	die "Failed to setup frontistr"
SOURCE_ESCAPED=`echo "$SHELLPACK_SOURCES" | sed -e 's/\//\\\\\//g'`
sed -i -e "s/SHELLPACK_SOURCES/$SOURCE_ESCAPED/g" Makefile.conf ||
	die "Failed to set sources location"
sed -i -e "s/^PREFIX.*/PREFIX = $SOURCE_ESCAPED\/frontistr-$VERSION-installed/" Makefile.conf ||
	die "Failed to set prefix"
sed -i -e "s/METIS_VERSION/$METIS_VERSION/g" Makefile.conf
sed -i -e "s/TRILINOS_VERSION/$TRILINOS_VERSION/g" Makefile.conf
sed -i -e "s/REVOCAP_VERSION/$REVOCAP_VERSION/g" Makefile.conf
sed -i -e "s/MUMPS_VERSION/$MUMPS_VERSION/g" Makefile.conf
sed -i -e "s/SCALAPACK_VERSION/$SCALAPACK_VERSION/g" Makefile.conf
sed -i -e "s/TRILINOS_VERSION/$TRILINOS_VERSION/g" Makefile.conf
sed -i -e "s/BLAS_VERSION/$BLAS_VERSION/g" Makefile.conf
build_callback
./setup.sh -p -p --with-tools --with-refiner \
	--with-metis --with-mumps --with-lapack --with-ml

export MMTESTS_BUILD_SERIAL=yes
###SHELLPACK make_make_install

echo frontistr installed successfully
exit $SHELLPACK_SUCCESS

==== BEGIN FrontISTR-v5.0-Makefile.conf.org.diff ====
--- a/Makefile.conf	2020-08-12 16:20:44.823660158 +0100
+++ b/Makefile.conf	2020-08-12 16:21:12.827635765 +0100
@@ -18,30 +18,31 @@
 INCLUDEDIR     = $(PREFIX)/include
 
 # Metis
-METISDIR       = $(HOME)/Metis-4.0
-METISLIBDIR    = $(METISDIR)
-METISINCDIR    = $(METISDIR)/Lib
+METISDIR       = SHELLPACK_SOURCES/metisbuild-METIS_VERSION-installed
+METISLIBDIR    = $(METISDIR)/$(MMTESTS_LIBDIR)
+METISINCDIR    = $(METISDIR)/include
 HECMW_METIS_VER= 4
 
 # ParMetis
-PARMETISDIR    = $(HOME)/ParMetis-3.1
-PARMETISLIBDIR = $(PARMETISDIR)
-PARMETISINCDIR = $(PARMETISDIR)/ParMETISLib
+PARMETISDIR    = SHELLPACK_SOURCES/trilinosbuild-TRILINOS_VERSION-installed
+PARMETISLIBDIR = $(PARMETISDIR)/$(MMTESTS_LIBDIR)
+PARMETISINCDIR = $(PARMETISDIR)/include
 
 # Refiner
-REFINERDIR     = $(HOME)/REVOCAP_Refiner
-REFINERINCDIR  = $(REFINERDIR)/Refiner
-REFINERLIBDIR  = $(REFINERDIR)/lib
+REFINERDIR     = SHELLPACK_SOURCES/revocapbuild-REVOCAP_VERSION-installed
+REFINERINCDIR  = $(REFINERDIR)/include
+REFINERLIBDIR  = $(REFINERDIR)/$(MMTESTS_LIBDIR)
 
 # Coupler
-REVOCAPDIR     = $(HOME)/REVOCAP_Coupler
-REVOCAPINCDIR  = $(REVOCAPDIR)/librcap
-REVOCAPLIBDIR  = $(REVOCAPDIR)/librcap
+REVOCAPDIR     = SHELLPACK_SOURCES/revocapbuild-REVOCAP_VERSION-installed
+REVOCAPINCDIR  = $(REVOCAPDIR)/include
+REVOCAPLIBDIR  = $(REVOCAPDIR)/$(MMTESTS_LIBDIR)
 
 # MUMPS
-MUMPSDIR       = $(HOME)/MUMPS_4.10.0
+MUMPSDIR       = SHELLPACK_SOURCES/mumpsbuild-MUMPS_VERSION-installed
 MUMPSINCDIR    = $(MUMPSDIR)/include
 MUMPSLIBDIR    = $(MUMPSDIR)/lib
+MUMPSLIBS      = -ldmumps -lmumps_common -lpord -LSHELLPACK_SOURCES/mumpsbuild-MUMPS_VERSION-installed/$(MMTESTS_LIBDIR) -LSHELLPACK_SOURCES/scalapackbuild-SCALAPACK_VERSION-installed/$(MMTESTS_LIBDIR) -lscalapack
 
 # MKL PARDISO
 MKLDIR     = $(HOME)/
@@ -49,29 +50,30 @@
 MKLLIBDIR  = $(MKLDIR)/lib
 
 # ML
-MLDIR          = $(HOME)/trilinos/11.8.1/ml
+MLDIR          = SHELLPACK_SOURCES/trilinosbuild-TRILINOS_VERSION-installed
 MLINCDIR       = $(MLDIR)/include
-MLLIBDIR       = $(MLDIR)/lib
+MLLIBDIR       = $(MLDIR)/$(MMTESTS_LIBDIR)
+MLLIBS         = -lml -lamesos -ltrilinosss -lzoltan -lepetra -lteuchosremainder -lteuchosnumerics -lteuchoscomm -lteuchosparameterlist -lteuchoscore -ldmumps -lmumps_common -lpord -lmetis
 
 # C compiler settings
-CC             = mpicc
+CC             = mpicc -fopenmp
 CFLAGS         =
-LDFLAGS        = -lm
+LDFLAGS        = -lstdc++ -lm
 OPTFLAGS       = -O3
 
 # C++ compiler settings
-CPP            = mpic++
+CPP            = mpic++ -fopenmp
 CPPFLAGS       =
 CPPLDFLAGS     =
 CPPOPTFLAGS    = -O3
 
 # Fortran compiler settings
-F90            = mpif90
+F90            = mpif90 -fopenmp
 F90FLAGS       =
-F90LDFLAGS     =
+F90LDFLAGS     = -lstdc++ -LSHELLPACK_SOURCES/blasbuild-BLAS_VERSION-installed/$(MMTESTS_LIBDIR) -lopenblas
 F90OPTFLAGS    = -O2
 F90FPP         = -cpp
-F90LINKER      = mpif90
+F90LINKER      = mpif90 -fopenmp
 
 MAKE           = make
 AR             = ar ruv
==== END FrontISTR-v5.0-Makefile.conf.org.diff ====

